#include "CiniSet.h"
#include "shlwapi.h"
#pragma comment( lib, "shlwapi.lib" )

#define bufLen 4095
CIniSet::CIniSet()
{
	m_name[0] = '\0';
}

CIniSet::~CIniSet()
{
}

bool CIniSet::Open(char * FileName)
{
	char buf[bufLen];
	GetCurrentDirectory(bufLen, buf);
	strcat_s(buf, "\\");
	strcat_s(buf, FileName);
	if (!PathFileExists(buf))
		return false;
	strcpy_s(m_name, buf);
	return true;
}

bool CIniSet::Save(char *filename)
{
	return true;
}

bool CIniSet::WriteInt(char * AppName, char * KeyName, int num)
{
	char buf[100];
	_itoa_s(num, buf, 10);
	return WritePrivateProfileString(AppName, KeyName, buf, m_name);
}

bool CIniSet::WriteText(char *AppName, char *KeyName, char *str)
{
	return WritePrivateProfileString(AppName, KeyName, str, m_name);
}


int CIniSet::ReadInt(char *AppName, char *KeyName, int Default)
{
	return GetPrivateProfileInt(AppName, KeyName, Default, m_name);
}


char* CIniSet::ReadText(char *AppName, char *KeyName, char *Default)
{
	static char buf[bufLen];
	GetPrivateProfileString(AppName, KeyName, Default, buf, bufLen, m_name);
	return buf;
}
